package level;

import flixel.FlxSprite;
import flixel.group.FlxTypedGroup;
import flixel.FlxG;
import actions.BasicContainer;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;


class Robot extends ProgrammableActor{
	public var id(default, null): Int;
	private inline static var shotSpeed: Float = 100;		// velocidad de las balas
	//
	public function new (X: Float, Y: Float, Id: Int)
	{
		super();
		trace("creando ROBOT "+Id);
		loadGraphic("assets/img/robot.png");
		x = X;
		y = Y;
		id = Id;
		animation.frameIndex = 0;
		_robots.add(this);
	}

	public function bind()
	{
		
	}

	public override function reset(X: Float, Y: Float)
	{
		_asociatedContainer.startExecution();
		alpha = 1;
		color = 0xffffffff;
		super.reset(X, Y);
	}
	
	
	public override function kill(): Void
	{
		var options: TweenOptions = { type: FlxTween.ONESHOT, ease: FlxEase.quadIn, complete: onKillEndTween};
		// raro, no anda bien si el tween no dura 0.5
		FlxTween.color(this, 0.5, 0xffffff, 0xff0000, 1, 0, options);
	}

	private  function onKillEndTween(Tween: FlxTween)
	{
		super.kill();
	}

	public static function clearAll(){
		_robots.clear();
	}

	public static function findById(Id: Int)
	{
		for(robot in _robots.members)
		{
			if(robot.id == Id)
			{
				return robot;
			}
		}
		return null;
	}


	public static function getRobots(): FlxTypedGroup<Robot>
	{
		return _robots;
	}

	private static var _robots: FlxTypedGroup<Robot> = new FlxTypedGroup<Robot>();
}